package cc.autoapi.pucong.auto.flow.provider.aop.controller;

import cc.autoapi.pucong.auto.flow.core.root.entity.BatchDeleteIdDto;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowBaseController;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowExceptionHandler;
import cc.autoapi.pucong.auto.flow.core.root.utils.Res;
import cc.autoapi.pucong.auto.flow.provider.aop.entity.dto.ProjectAopRuleInsertDto;
import cc.autoapi.pucong.auto.flow.provider.aop.entity.dto.ProjectAopRuleUpdateDto;
import cc.autoapi.pucong.auto.flow.provider.aop.entity.qo.ProjectAopRuleQo;
import cc.autoapi.pucong.auto.flow.provider.aop.entity.vo.ProjectAopRuleVo;
import cc.autoapi.pucong.auto.flow.provider.aop.manager.AopRuleManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @url https://gitee.com/pucong
 * @create 2023-11-21
 */
@RestController
@RequestMapping("/aop/rule")
public class ProjectAopRuleController extends AutoFlowBaseController implements AutoFlowExceptionHandler {

    @Autowired
    private AopRuleManager aopRuleManager;

    @GetMapping("/getProjectAopRuleList")
    public Res<List<ProjectAopRuleVo>> getProjectAopRuleList(ProjectAopRuleQo projectAopRuleQo) {
        List<ProjectAopRuleVo> projectAopRuleList = aopRuleManager.getProjectAopRuleList(projectAopRuleQo.getAopId());
        return Res.ok(projectAopRuleList);
    }

    @GetMapping("/getProjectAopRuleById/{id}")
    public Res<ProjectAopRuleVo> getProjectAopRuleById(@PathVariable("id") String id) {
        ProjectAopRuleVo vo = aopRuleManager.getProjectAopRuleById(id);
        return Res.ok(vo);
    }

    @PostMapping("/insertProjectAopRule")
    public Res<Integer> insertProjectAopRule(@Validated @RequestBody ProjectAopRuleInsertDto dto) {
        int i = aopRuleManager.insertProjectAopRule(dto);
        return Res.ok(i);
    }

    @PutMapping("/updateProjectAopRuleById/{id}")
    public Res<Integer> updateProjectAopRuleById(@PathVariable("id") String id,
                                                 @Validated @RequestBody ProjectAopRuleUpdateDto dto) {
        int i = aopRuleManager.updateProjectAopRuleById(id, dto);
        return Res.ok(i);
    }


    @DeleteMapping("/batchDeleteProjectAopRuleByIds")
    public Res<Integer> batchDeleteProjectAopRuleByIds(BatchDeleteIdDto dto) {
        int i = aopRuleManager.batchDeleteProjectAopRuleByIds(dto.getIdList());
        return Res.ok(i);
    }
}